<!doctype html>
<html>
<head>
    <include file="public/head"/>
    <title>编辑字段</title>
    <meta name="description" content="编辑字段">
    <meta name="keywords" content="编辑字段">
</head>
<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li><a href="{:cmf_plugin_url('QbtCustomModel://AdminIndex/index')}">模型管理</a></li>
        <li><a href="{:cmf_plugin_url('QbtCustomModel://AdminQbtCustomModel/add')}">添加模型</a></li>
		<li><a href="{:cmf_plugin_url('QbtCustomModel://AdminModelField/lists',['model_id'=>$model_info['model_id']])}">字段管理</a></li>
		<li><a href="{:cmf_plugin_url('QbtCustomModel://AdminModelField/add',['model_id'=>$model_info['model_id']])}">添加字段</a></li>
		<li class="active"><a>编辑字段</a></li>
    </ul>
    <form method="post" class="form-horizontal js-ajax-form margin-top-20"
          action="{:cmf_plugin_url('QbtCustomModel://AdminModelField/editPost')}">
		  
		<div class="form-group">
            <label class="col-sm-2 control-label">所属模型</label>
            <div class="col-md-6 col-sm-10" style="line-height:35px;">
                <span style="color:red;">{$model_info.model_name}</span>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-2 control-label"><span class="form-required">*</span>字段名称</label>
            <div class="col-md-6 col-sm-10">
                <input type="text" class="form-control" name="field_name" value="{$field_info.field_name}">
				<p>只能由英文字母、数字和下划线组成，并且仅能字母开头，不以下划线结尾</p>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label"><span class="form-required">*</span>字段别名</label>
            <div class="col-md-6 col-sm-10">
                <input type="text" class="form-control" name="field_nikename" value="{$field_info.field_nikename}">
				<p>例如：文章标题</p>
            </div>
        </div>
		<div class="form-group">
			<label for="input-controller" class="col-sm-2 control-label"><span class="form-required">*</span>字段类型</label>
			<div class="col-md-6 col-sm-10">
				<select name="field_type" class="form-control" onchange="field_setting($(this));">
					<foreach name="formtype" item="vo" key="key">
					<option value="{$key}" <eq name="key" value="$field_info.field_type">selected="selected"</eq>>{$vo}</option>
					</foreach>
				</select>
				<p>显示在字段别名下方作为表单输入提示</p>
			</div>
		</div>
		<div id="inputstyle">
			<?php if($field_info['field_type'] == 'textarea'):?>
				<div class="form-group">
					<label class="col-sm-2 control-label">字段属性</label>
					<div class="col-md-6 col-sm-10">
						<select name="field_type2" class="form-control">
							<option value="varchar" <eq name="field_info.field_type2" value="varchar">selected="selected"</eq>>文本(VARCHAR)</option>
							<option value="text" <eq name="field_info.field_type2" value="text">selected="selected"</eq>>小型文本(TINYINT)</option>
							<option value="mediumtext" <eq name="field_info.field_type2" value="mediumtext">selected="selected"</eq>>中型文本(MEDIUMTEXT)</option>
							<option value="longtext" <eq name="field_info.field_type2" value="text">selected="selected"</eq>>大型文本(TEXT)</option>
							<option value="longtext" <eq name="field_info.field_type2" value="longtext">selected="selected"</eq>>超大型文本(LONGTEXT)</option>
						</select>
					</div>
				</div>
			<?php elseif($field_info['field_type'] == 'html'):?>
				<div class="form-group">
					<label class="col-sm-2 control-label">字段属性</label>
					<div class="col-md-6 col-sm-10">
						<select name="field_type2" class="form-control">
							<option value="text" <eq name="field_info.field_type2" value="text">selected="selected"</eq>>小型文本(TINYINT)</option>
							<option value="mediumtext" <eq name="field_info.field_type2" value="mediumtext">selected="selected"</eq>>中型文本(MEDIUMTEXT)</option>
							<option value="longtext" <eq name="field_info.field_type2" value="text">selected="selected"</eq>>大型文本(TEXT)</option>
							<option value="longtext" <eq name="field_info.field_type2" value="longtext">selected="selected"</eq>>超大型文本(LONGTEXT)</option>
						</select>
					</div>
				</div>
			<?php elseif($field_info['field_type'] == 'number'):?>
				<div class="form-group">
					<label class="col-sm-2 control-label">字段属性</label>
					<div class="col-md-6 col-sm-10">
						<select name="field_type2" class="form-control">
							<option value="tinyint" <eq name="field_info.field_type2" value="tinyint">selected="selected"</eq>>小整数(TINYINT)</option>
							<option value="smallint" <eq name="field_info.field_type2" value="smallint">selected="selected"</eq>>大整数(SMALLINT)</option>
							<option value="mediumint" <eq name="field_info.field_type2" value="mediumint">selected="selected"</eq>>大整数(MEDIUMINT)</option>
							<option value="int" <eq name="field_info.field_type2" value="int">selected="selected"</eq>>极大整数(INT)</option>
							<option value="bigint" <eq name="field_info.field_type2" value="bigint">selected="selected"</eq>>超大整数(BIGINT)</option>
						</select>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label">字段长度</label>
					<div class="col-md-6 col-sm-10">
						<input type="text" class="form-control" name="field_length" value="{$field_info.field_length}">
						<p>不填会默认</p>
					</div>
				</div>
			<?php elseif($field_info['field_type'] == 'float'):?>
				<div class="form-group">
					<label class="col-sm-2 control-label">字段属性</label>
					<div class="col-md-6 col-sm-10">
						<select name="field_type2" class="form-control">
							<option value="float" <eq name="field_info.field_type2" value="float">selected="selected"</eq>>浮点(FLOAT)</option>
							<option value="double" <eq name="field_info.field_type2" value="double">selected="selected"</eq>>双精度(DOUBLE)</option>
							<option value="decimal" <eq name="field_info.field_type2" value="decimal">selected="selected"</eq>>小数值(DECIMAL)</option>
						</select>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label">字段长度</label>
					<div class="col-md-6 col-sm-10">
						<input type="text" class="form-control" name="field_length" value="{$field_info.field_length}">
						<p>不填会默认</p>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label">小数位数</label>
					<div class="col-md-6 col-sm-10">
					<input type="text" class="form-control" name="field_digits" value="{$field_info.field_digits}">
					</div>
				</div>
			<?php elseif($field_info['field_type'] == 'text'):?>
				<div class="form-group">
					<label class="col-sm-2 control-label">字段长度</label>
					<div class="col-md-6 col-sm-10">
						<input type="text" class="form-control" name="field_length" value="{$field_info.field_length}">
						<p>不填会默认</p>
					</div>
				</div>
			<?php elseif($field_info['field_type'] == 'outreach'):?>
			<div class="form-group">
				<label class="col-sm-2 control-label">关联数据</label>
				<div class="col-md-6 col-sm-10">
				<input type="text" class="form-control" name="field_outreach" id="field_outreach" value="{$field_info.field_outreach}">
				<label class="control-label">
				<a href="javascript:get_table($(this))">点击选择</a>
				</label>
				</div>
			</div>
			<?php elseif($field_info['field_type'] == 'file'):?>
			<div class="form-group">
				<label class="col-sm-2 control-label">文件类型</label>
				<div class="col-md-6 col-sm-10">
					<select name="field_file_type" class="form-control">
						<option value="image" <eq name="field_info.field_file_type" value="image">selected="selected"</eq>>图片</option>
						<option value="video" <eq name="field_info.field_file_type" value="video">selected="selected"</eq>>视频</option>
						<option value="audio" <eq name="field_info.field_file_type" value="audio">selected="selected"</eq>>音频</option>
						<option value="file"  <eq name="field_info.field_file_type" value="file">selected="selected"</eq>>文件</option>
					</select>
				</div>
			</div>
			<?php endif;?>
		</div>
		
		<div class="form-group">
            <label class="col-sm-2 control-label">默认值</label>
            <div class="col-md-6 col-sm-10">
                <textarea name="field_default" class="form-control">{$field_info.field_default}</textarea>
				<p>多选用英文逗号隔开，单选下拉，填0,1对应可选项第一个第二个...</p>
            </div>
        </div>
		
		<div class="form-group">
            <label class="col-sm-2 control-label">可选项</label>
            <div class="col-md-6 col-sm-10">
                <textarea name="field_choose" class="form-control">{$field_info.field_choose}</textarea>
				<p>如果是单选，多选，下拉的话多个值用回车请换行【自定义键值 例如：1=男】</p>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-2 control-label">字段提示</label>
            <div class="col-md-6 col-sm-10">
                <textarea name="field_tips" class="form-control">{$field_info.field_tips}</textarea>
				<p>添加修改数据的时候后面的提示</p>
            </div>
        </div>

		<div class="form-group">
            <label class="col-sm-2 control-label">字符长度</label>
            <div class="col-md-6 col-sm-10">
                最小值：<input name="field_min_length" value="{$field_info.field_min_length}" maxlength="6" onkeyup="value=value.replace(/[^\d]/g,'')"/> &nbsp;&nbsp;&nbsp;&nbsp; 最大值：<input name="field_max_length" value="{$field_info.field_max_length}" maxlength="6" onkeyup="value=value.replace(/[^\d]/g,'')"/>
				<p>系统将在表单提交时检测数据长度范围是否符合要求，如果不想限制长度请留空</p>
            </div>
        </div>
		<div class="form-group">
            <label class="col-sm-2 control-label">必填项</label>
            <div class="col-md-6 col-sm-10">
                <select class="form-control valid" name="field_is_required" id="input-status" aria-invalid="false">
                    <option value="0" <eq name="$field_info.field_is_required" value="0">selected="selected"</eq>>非必填</option>
                    <option value="1" <eq name="$field_info.field_is_required" value="1">selected="selected"</eq>>必填</option>
                </select>
            </div>
        </div>
		
		<div class="form-group">
			<label class="col-sm-2 control-label">正则校验</label>
			<div class="col-md-6 col-sm-10">
				<input type="text" class="form-control" name="field_regex" value="{$field_info.field_regex}">
			</div>
		</div>
		
        <div class="form-group">
            <label class="col-sm-2 control-label">是否启用</label>
            <div class="col-md-6 col-sm-10">
                <select class="form-control valid" name="field_status" id="input-status" aria-invalid="false">
                    <option value="1" <eq name="$field_info.field_status" value="1">selected="selected"</eq>>启用</option>
                    <option value="0" <eq name="$field_info.field_status" value="0">selected="selected"</eq>>禁用</option>
                </select>
            </div>
        </div>
		
		<div class="form-group">
            <label class="col-sm-2 control-label">添加页展示</label>
            <div class="col-md-6 col-sm-10">
                <select class="form-control valid" name="field_add_show" id="input-status" aria-invalid="false">
                    <option value="1" <eq name="$field_info.field_add_show" value="1">selected="selected"</eq>>展示</option>
                    <option value="0" <eq name="$field_info.field_add_show" value="0">selected="selected"</eq>>不展示</option>
                </select>
				<p>是否在添加或者编辑页面展示</p>
            </div>
        </div>
		<div class="form-group">
			<label class="col-sm-2 control-label">修改页展示</label>
			<div class="col-md-6 col-sm-10">
				<select class="form-control valid" name="field_edit_show" id="input-status" aria-invalid="false">
					<option value="1" <eq name="$field_info.field_edit_show" value="1">selected="selected"</eq>>展示</option>
					<option value="0" <eq name="$field_info.field_edit_show" value="0">selected="selected"</eq>>不展示</option>
				</select>
				<p>是否在添加或者编辑页面展示</p>
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-2 control-label">添加修改页展示多列</label>
			<div class="col-md-6 col-sm-10">
				<select class="form-control valid" name="field_add_edit_show_many_column" id="input" aria-invalid="false">
					<option value="0" <eq name="$field_info.field_add_edit_show_many_column" value="0">selected="selected"</eq>>单列</option>
					<option value="1" <eq name="$field_info.field_add_edit_show_many_column" value="1">selected="selected"</eq>>多列</option>
				</select>
				<p>是否在添加或者编辑页面展示</p>
			</div>
		</div>
		<div class="form-group">
            <label class="col-sm-2 control-label">列表页展示</label>
            <div class="col-md-6 col-sm-10">
                <select class="form-control valid" name="field_is_index" id="input-status" aria-invalid="false">
                    <option value="0" <eq name="$field_info.field_is_index" value="0">selected="selected"</eq>>不展示</option>
                    <option value="1" <eq name="$field_info.field_is_index" value="1">selected="selected"</eq>>展示</option>
                </select>
				<p>是否在列表页展示</p>
            </div>
        </div>

        <div class="col-sm-offset-2 col-sm-10">
			<input type="hidden" name="model_id" value="{$model_info.model_id}"/>
			<input type="hidden" name="field_id" value="{$field_info.field_id}"/>
			<input type="hidden" name="oldname" value="{$field_info.field_name}"/>
            <button type="submit" class="btn btn-primary js-ajax-submit">{:lang("SAVE")}</button>
        </div>
    </form>
</div>
<script type="text/javascript">

	function field_setting(obj){

		$("#inputstyle").empty();
		var val = $(obj).val();
		if(val == "textarea"){
			$("#inputstyle").html(inputStyles.textarea())
		}else if(val == "html"){
			$("#inputstyle").html(inputStyles.html())
		}else if(val == "number"){
			$("#inputstyle").html(inputStyles.number())
		}else if(val == "float"){
			$("#inputstyle").html(inputStyles.float())
		}else if(val == "text"){
			$("#inputstyle").html(inputStyles.text())
		}else if(val == "file"){
			$("#inputstyle").html(inputStyles.file())
		}else if(val == "files"){
			$("#inputstyle").html(inputStyles.files())
		}else if(val == "outreach"){
            $("#inputstyle").html(inputStyles.outreach())
        }
	}
	
	var inputStyles = {
		"text":function(){
			return '<div class="form-group"><label class="col-sm-2 control-label">字段长度</label><div class="col-md-6 col-sm-10"><input type="text" class="form-control" name="field_length" value=""><p>不填会默认</p></div></div>';
		},
		"textarea":function(){
			return '<div class="form-group"><label class="col-sm-2 control-label">字段属性</label><div class="col-md-6 col-sm-10"><select name="field_type2" class="form-control"><option value="varchar">文本(VARCHAR)</option><option value="text">小型文本(TINYINT)</option><option value="mediumtext">中型文本(MEDIUMTEXT)</option><option value="text">大型文本(TEXT)</option><option value="longtext">超大型文本(LONGTEXT)</option></select></div></div>';
		},
		"html":function(){
			return '<div class="form-group"><label class="col-sm-2 control-label">字段属性</label><div class="col-md-6 col-sm-10"><select name="field_type2" class="form-control"><option value="text">小型文本(TINYINT)</option><option value="mediumtext">中型文本(MEDIUMTEXT)</option><option value="text">大型文本(TEXT)</option><option value="longtext">超大型文本(LONGTEXT)</option></select></div></div>';
		},
		"number":function(){
			return '<div class="form-group">	<label class="col-sm-2 control-label">字段属性</label>	<div class="col-md-6 col-sm-10">		<select name="field_type2" class="form-control">			<option value="tinyint">小整数(TINYINT)</option>			<option value="smallint">大整数(SMALLINT)</option>			<option value="mediumint">大整数(MEDIUMINT)</option>			<option value="int">极大整数(INT)</option>			<option value="bigint">超大整数(BIGINT)</option>		</select>	</div></div><div class="form-group"><label class="col-sm-2 control-label">字段长度</label><div class="col-md-6 col-sm-10"><input type="text" class="form-control" name="field_length" value=""><p>不填会默认</p></div></div>';
		},
		"float":function(){
			return '<div class="form-group">	<label class="col-sm-2 control-label">字段属性</label>	<div class="col-md-6 col-sm-10">		<select name="field_type2" class="form-control">			<option value="float">浮点(FLOAT)</option>			<option value="double">双精度(DOUBLE)</option>			<option value="decimal">小数值(DECIMAL)</option>		</select>	</div></div> <div class="form-group"><label class="col-sm-2 control-label">字段长度</label><div class="col-md-6 col-sm-10"><input type="text" class="form-control" name="field_length" value=""><p>不填会默认</p></div></div><div class="form-group"><label class="col-sm-2 control-label">小数位数</label><div class="col-md-6 col-sm-10"><input type="text" class="form-control" name="field_digits" value="0"></div></div>';
		},
		"outreach":function(){
			return '<div class="form-group"><label class="col-sm-2 control-label">关联数据</label><div class="col-md-6 col-sm-10"><input type="text" class="form-control" name="field_outreach" id="field_outreach" value=""><label class="control-label"><a href="javascript:get_table($(this))">点击选择</a></label></div></div>';
		},"file":function(){
			return '<div class="form-group"><label class="col-sm-2 control-label">文件类型</label><div class="col-md-6 col-sm-10"><select name="field_file_type" class="form-control"><option value="image">图片</option><option value="video">视频</option><option value="audio">音频</option><option value="file">文件</option></select></div></div>';
		},"files":function(){
			return '<div class="form-group"><label class="col-sm-2 control-label">文件类型</label><div class="col-md-6 col-sm-10"><select name="field_file_type" class="form-control"><option value="image">图片</option><option value="video">视频</option><option value="audio">音频</option><option value="file">文件</option></select></div></div>';
		}
	
	}
	
	
	function get_table(obj){
	
		layer.open({
		  title:'获取关联数据',
		  type: 2,
		  btn: ['确定','取消'],
		  area: ['390px', '330px'], 
		  content: '{:cmf_plugin_url("QbtCustomModel://AdminModelField/getTable")}',
		  yes:function(index, layero){
				var table_name = layero.find("iframe")[0].contentWindow.$("#table_name").val();
				var field_name = layero.find("iframe")[0].contentWindow.$("#field_name").val();
				var show_name = layero.find("iframe")[0].contentWindow.$("#show_name").val();
				$("#field_outreach").val(table_name + "." + field_name + "." + show_name);
				layer.close(index);
		  },btn2: function(index){ //或者使用btn2
				
			}
		});		
	}
	
	
</script>

<include file="public/scripts"/>
</body>
</html>